package dao;

import pojo.Menu;
import utils.DbUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MenuDaoImpl extends DbUtils implements MenuDao {
    @Override
    public List<Menu> selectAll() {
        String sql = "select * from menu";
        ResultSet query = query(sql, null);
        List<Menu> menuList = new ArrayList<>();
        try {
            while (query.next()){
                Menu m =new Menu();
                m.setMenuId(query.getInt("menuid"));
                m.setMenuName(query.getString("menuname"));
                m.setUpmenuId(query.getInt("upmenuid"));
                m.setState(query.getInt("state"));
                m.setDesc(query.getString("desc"));
                m.setUrl(query.getString("url"));
                menuList.add(m);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return menuList;
    }
}
